package com.vecspace.utils;

/**当 append 的值为 null时，不做任何操作（原始StringBuilder append null时，为将null转为 "null" 字符串）
 * 
 * @version 1.0
 * @author wanghua
 * @reviewer  
 */
public class StringBuilderEx{
	private StringBuilder strBuilder;

	public StringBuilderEx() {
		strBuilder = new StringBuilder();
	}

	public StringBuilderEx(int capacity) {
		strBuilder = new StringBuilder(capacity);
	}

	/**如果str为null,不做任何操作，而不是append  "null" 字符串。
	 * 
	 * @param str
	 * @return 
	 * @author wanghua
	 * @reviewer  
	 */
	public StringBuilderEx append(String value) {
		if(value != null) {
			strBuilder.append(value);
		}
		return this;
	}

	public StringBuilderEx append(int value) {	
		strBuilder.append(value);
		return this;	
	}

	public StringBuilderEx append(double value) {
		strBuilder.append(value);
		return this;
	}

	public StringBuilderEx append(float value) {
		strBuilder.append(value);
		return this;
	}

	public StringBuilderEx append(Object value) {
		if(value != null) {
			strBuilder.append(value);
		}
		return this;
	}

	public StringBuilderEx append(char value) {
		strBuilder.append(value);
		return this;
	}

	public StringBuilderEx append(Integer value) {
		if(value != null) {
			strBuilder.append(value);
		}
		return this;
	}

	public StringBuilderEx delete(int start, int end) {
		strBuilder.delete(start, end);
		return this;
    }

    public StringBuilderEx deleteCharAt(int index) {
    	strBuilder.deleteCharAt(index);
		return this;
    }
    
    public int length() {
    	return strBuilder.length();
    }

	@Override
	public String toString() {		
		return strBuilder.toString();
	}
}
